home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / RCS / Ulog_ClearLogins.c,v < prev    next >
Encoding:
Text File  |  1989-01-13  |  3.1 KB  |  156 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.01.13.11.49.52;  author douglis;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     89.01.06.12.36.39;  author douglis;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @Void any user log records for the current host.
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @tell Db_Open how many records to buffer.
  28. @
  29. text
  30. @/* 
  31.  * Ulog_ClearLogins.c --
  32.  *
  33.  *    Source code for the Ulog_ClearLogins procedure.
  34.  *
  35.  * Copyright 1988 Regents of the University of California
  36.  * Permission to use, copy, modify, and distribute this
  37.  * software and its documentation for any purpose and without
  38.  * fee is hereby granted, provided that the above copyright
  39.  * notice appear in all copies.  The University of California
  40.  * makes no representations about the suitability of this
  41.  * software for any purpose.  It is provided "as is" without
  42.  * express or implied warranty.
  43.  */
  44.  
  45. #ifndef lint
  46. static char rcsid[] = "$Header: /sprite/src/lib/c/ulog/RCS/Ulog_ClearLogins.c,v 1.1 89/01/06 12:36:39 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  47. #endif not lint
  48.  
  49.  
  50. #include <ulog.h>
  51. #include "ulogInt.h"
  52.  
  53.  
  54. /*
  55.  *----------------------------------------------------------------------
  56.  *
  57.  * Ulog_ClearLogins --
  58.  *
  59.  *    Void any user log records for the current host.
  60.  *
  61.  * Results:
  62.  *    0 on success, -1 if an error occurs (and errno will indicate the
  63.  *    nature of the error).
  64.  *
  65.  * Side effects:
  66.  *    The 'user log' is opened and locked while it is being modified.
  67.  *
  68.  *----------------------------------------------------------------------
  69.  */
  70.  
  71.  
  72. int
  73. Ulog_ClearLogins()
  74. {
  75.     char myHostName[ULOG_LOC_LENGTH];
  76.     char buffer[ULOG_RECORD_LENGTH];
  77.     Host_Entry *hostPtr;
  78.     Db_Handle handle;
  79.     int errnoTmp;
  80.     int i;
  81.  
  82.     if (gethostname(myHostName, ULOG_LOC_LENGTH) < 0) {
  83.     syslog(LOG_ERR, "Ulog_ClearLogins: error in gethostname.\n");
  84.     return(-1);
  85.     }
  86.     hostPtr = Host_ByName(myHostName);
  87.     Host_End();
  88.     if (hostPtr == (Host_Entry *) NULL) {
  89.     syslog(LOG_ERR,
  90.            "Ulog_ClearLogins: error in Host_ByName for current host.\n");
  91.     return(-1);
  92.     }
  93.  
  94.     if (Db_Open(ULOG_FILE_NAME, ULOG_RECORD_LENGTH, &handle, 1,
  95.              DB_LOCK_OPEN, DB_LOCK_BREAK, 0) < 0) {
  96.     return(-1);
  97.     }
  98.  
  99.     bzero(buffer, ULOG_RECORD_LENGTH);
  100.     (void) sprintf(buffer, ULOG_FORMAT_STRING, -1, hostPtr->id, -1,
  101.          0, "(none)");
  102.  
  103.     /*
  104.      * Write the first entry, specifying the location.  Then do writes
  105.      * sequentially (avoiding seeks).
  106.      */
  107.  
  108.     if (Db_Put(&handle, buffer, hostPtr->id * ULOG_MAX_PORTS) < 0) {
  109.     goto error;
  110.     }
  111.     
  112.     for (i = 1; i < ULOG_MAX_PORTS; i++) {
  113.     if (Db_Put(&handle, buffer, -1) < 0) {
  114.         goto error;
  115.     }
  116.     }
  117.     if (Db_Close(&handle) < 0) {
  118.     return(-1);
  119.     }
  120.     return(0);
  121.  
  122.  
  123.     /*
  124.      * On error, try to close the database, but make sure to return
  125.      * the error in errno that came from the error that made us quit.
  126.      */
  127. error:
  128.     errnoTmp = errno;
  129.     (void) Db_Close(&handle);
  130.     errno = errnoTmp;
  131.  
  132.     return(-1);
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. @
  142.  
  143.  
  144. 1.1
  145. log
  146. @Initial revision
  147. @
  148. text
  149. @d17 1
  150. a17 1
  151. static char rcsid[] = "$Header: Ulog_ClearLogins.c,v 1.3 88/09/15 10:16:58 douglis Exp $ SPRITE (Berkeley)";
  152. d66 1
  153. a66 1
  154.              DB_LOCK_OPEN, DB_LOCK_BREAK) < 0) {
  155. @
  156.